<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateInstallmentsTable extends Migration
{
    public function up()
    {
        Schema::create('installments', function (Blueprint $table) {
            $table->id();
            //分期流水号
            $table->string('no')->unique();
            //用户 ID
            $table->unsignedBigInteger('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            //对应的商品订单 ID
            $table->unsignedBigInteger('order_id');
            $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
            //总本金
            $table->decimal('total_amount');
            //还款期数
            $table->unsignedInteger('count');
            //手续费率
            $table->float('fee_rate');
            //逾期费率
            $table->float('fine_rate');
            //还款状态
            $table->string('status')->default(\App\Models\Installment::STATUS_PENDING);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('installments');
    }
}
